/*
 * @Description: 
 * @Author: charles
 * @Date: 2021-09-23 17:01:50
 * @LastEditors: charles
 * @LastEditTime: 2021-10-21 16:39:14
 */
import axios from 'axios'
import qs from 'qs'
import { Notify } from 'vant';

const instance = axios.create({
  baseURL: 'http://121.199.29.84:8001',
  timeout: 10000
});
instance.interceptors.request.use((config)=>{
  let token = localStorage.getItem('token')
  if(token){
    config.headers.Authorization = token;
  }
  return config;
})
instance.interceptors.response.use(({data:resp})=>{
  if(resp.status === 200){
    return resp;
  }
  Notify({type:"danger",message:resp.message});
  return Promise.reject(resp)
},(error)=>{
  Notify({type:"danger",message:'交互异常'});
  return Promise.reject(error)
})


// url {id:1}
export function get(url,params){
  return instance.get(url,{ params })
}
export function post(url,data){
  data = qs.stringify(data)
  return instance.post(url,data,{
    headers:{
      'Content-Type':'application/x-www-form-urlencoded'
    }
  })
}
export function postJSON(url,data){
  return instance.post(url,data)
}
export function del(url,params) {
  return instance.delete(url,{params})
}
export default instance;

// ...